/* GUI CONVERTED from rcmrwa.p (converter v1.76) Sun May 19 19:42:55 2002 */
/* rcmrwa.p - Release Management Customer Schedules                           */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.4.1.11 $                                                         */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.0    LAST MODIFIED: 01/29/92    BY: WUG *F110*                 */
/* REVISION: 7.0    LAST MODIFIED: 03/23/92    BY: WUG *F312*                 */
/* REVISION: 7.3    LAST MODIFIED: 12/23/92    BY: WUG *G471*                 */
/* REVISION: 7.3    LAST MODIFIED: 08/13/93    BY: WUG *GE19*                 */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98    BY: *K1Q4* Alfred Tan          */
/* REVISION: 8.6E   LAST MODIFIED: 07/10/98    BY: *H1LW* Surekha Joshi       */
/* REVISION: 8.6E   LAST MODIFIED: 04/06/99    BY: *K208* Surekha Joshi       */
/* REVISION: 9.1    LAST MODIFIED: 04/25/00    BY: *N0CF* Santosh Rao         */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00    BY: *N0KP* Mark Brown          */
/* REVISION: 9.1    LAST MODIFIED: 10/09/00    BY: *N0R9* Jean Miller         */
/* REVISION: 9.1    LAST MODIFIED: 11/08/00    BY: *N0TN* Jean Miller         */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.4.1.8   BY: Jean Miller         DATE: 03/22/01 ECO: *P008*     */
/* $Revision: 1.4.1.11 $  BY: Rajiv Ramaiah       DATE: 09/19/01 ECO: *M1LM*     */
/* Revision:$          BY: Lena Lim            DATE:05/20/2002 ECO: *P070*   */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* UPDATE MRP DETAIL SUBPROGRAM */
{mfdeclre.i}
{gplabel.i}

/* Input Parameters */
define input parameter order_nbr as character.
define input parameter order_line as integer.
define input parameter schedule_change like mfc_logical.

define variable req_schedule      as integer initial 3.
define variable i                 as integer.
define variable prior_cum_net_req as decimal.
define variable cum_net_req       as decimal.
define variable net_req           as decimal.
define variable l_mrpref          as character no-undo.

for first sod_det
fields(sod_cum_qty sod_curr_rlse_id sod_line sod_nbr sod_part sod_site)
where sod_nbr  = order_nbr and
      sod_line = order_line no-lock:
end. /* FOR FIRST SOD_DET */

if schedule_change then do:

   /* WE NEED TO COMPLETELY REFRESH SO DELETE EVERYTHING */
   for each mrp_det where
            mrp_dataset = "cs sch_mstr"
        and mrp_part = sod_part
        and mrp_nbr = sod_nbr
        and mrp_line = string(sod_line)
   exclusive-lock:
      delete mrp_det.
   end.

   {inmrp.i &part=sod_part &site=sod_site}

end.

for first sch_mstr
fields(sch_line sch_nbr sch_pcr_qty sch_pcs_date sch_rlse_id sch_type)
where sch_type = req_schedule
  and sch_nbr = sod_nbr
  and sch_line = sod_line
  and sch_rlse_id = sod_curr_rlse_id[req_schedule]
no-lock: end. /* FOR FIRST SCH_MSTR */

if available sch_mstr then do:

   for first so_mstr
   fields (so_nbr so_cum_acct)
   where so_nbr = sod_nbr
   no-lock: end. /* FOR FIRST SO_MSTR */

   i = 1.

   if so_cum_acct then do:

      prior_cum_net_req = max(sch_pcr_qty - sod_cum_qty[1],0).

      {mfmrw.i "cs sch_mstr" sod_part sod_nbr string(sod_line) """"
         ? sch_pcs_date prior_cum_net_req "demand"
         CUSTOMER_SCHEDULE sod_site}

   end. /* IF SO_CUM_ACCT */

   for each schd_det
      where schd_type = sch_type
        and schd_nbr = sch_nbr
        and schd_line = sch_line
        and schd_rlse_id = sch_rlse_id
   no-lock:
/*GUI*/ if global-beam-me-up then undo, leave.


      if so_cum_acct then do:
         assign
            cum_net_req       = max(schd_cum_qty - sod_cum_qty[1],0)
            net_req           = cum_net_req - prior_cum_net_req
            prior_cum_net_req = cum_net_req.
      end. /* IF SO_CUM_ACCT */
      else
         net_req = max(schd_discr_qty - schd_ship_qty,0).

      {mfmrw.i "cs sch_mstr" sod_part sod_nbr string(sod_line) string(i)
         ? schd_date net_req "demand" CUSTOMER_SCHEDULE sod_site}

      for each pk_det
         fields (pk_part pk_user)
         where pk_user = mfguser
         no-lock:
/*GUI*/ if global-beam-me-up then undo, leave.


         l_mrpref = string(sod_line,"9999")
                    + string(year(schd_date),"9999")
                    + string(month(schd_date),"99")
                    + string(day(schd_date),"99")
                    + schd_time
                    + schd_reference.

         {mfmrw.i "pb_sold" pk_part sod_nbr l_mrpref """"
          ? schd_date net_req "demand" SALES sod_site}

      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR EACH pk_det */

      i = i + 1.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* for each schd_det */

end. /* if available sch_mstr */

{mfdel.i pk_det "where pk_user = mfguser"}
